# Copyright 2018- The Pixie Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
load("//bazel/cc_toolchains:gcc.bzl", "gcc_x86_64_gnu")
load("//bazel/cc_toolchains:llvm_libs.bzl", "llvm_variant_settings")
load("//bazel/cc_toolchains:settings.bzl", "settings")

filegroup(
    name = "empty",
)

settings()

llvm_variant_settings()

gcc_x86_64_gnu()

constraint_setting(
    name = "is_exec",
    default_constraint_value = ":is_exec_true",
    visibility = ["//visibility:public"],
)

constraint_value(
    name = "is_exec_true",
    constraint_setting = ":is_exec",
    visibility = ["//visibility:public"],
)

constraint_value(
    name = "is_exec_false",
    constraint_setting = ":is_exec",
    visibility = ["//visibility:public"],
)

# This is the platform we currently target. All builds for other platforms will use the default value of `is_exec` which is `is_exec_true`.
# This forces all builds not for the target platform, to use the toolchain provided in `clang_exec` which doesn't support sanitizers.
# Once this issue https://github.com/bazelbuild/bazel/issues/13839 is fixed, this can be removed entirely. Because
# the issue here is that the --features=asan flag applies to host/exec builds also.
# The GCC toolchain doesn't specify an `is_exec` constraint setting so it works for both constraint values.
platform(
    name = "linux-x86_64",
    constraint_values = [
        "@platforms//os:linux",
        "@platforms//cpu:x86_64",
        # This is used to force disabling of asan,msan,tsan etc for host
        ":is_exec_false",
    ],
)

platform(
    name = "linux-aarch64",
    constraint_values = [
        "@platforms//os:linux",
        "@platforms//cpu:aarch64",
        ":is_exec_false",
    ],
)
